package com.daixu.xutil.demo.utils;

import java.io.File;
import java.io.IOException;

public class FileUtils {

	/*******************************************************
	 * 说明：创建文件
	 * @param filePath
	 * @return
	 *******************************************************/
    public static boolean createFile(String filePath) {
        File file = new File(filePath);
        if (!file.exists()) {
            try {
                return file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return false;
    }

	/*******************************************************
	 * 说明：创建文件夹
	 * @param dirPath
	 * @return
	 *******************************************************/
    public static boolean createDir(String dirPath) {
        File file = new File(dirPath);
        if (!file.exists()) {
            return file.mkdirs();
        }
        return false;
    }

	/*******************************************************
	 * 说明：删除文件
	 * @param filePath
	 *******************************************************/
	public static void deleteFile(String filePath) {
		File file = new File(filePath);
		file.delete();
	}

	/*******************************************************
	 * 说明：删除文件夹
	 * @param dirPath
	 *******************************************************/
	public static void deleteDir(String dirPath) {
		File dirFile = new File(dirPath);
		if (dirFile.isFile()) {
			dirFile.delete();
			return;
		}
		if (dirFile.isDirectory()) {
			File[] fileList = dirFile.listFiles();
			if (fileList == null || fileList.length == 0) {
				dirFile.delete();
				return;
			}
			for (int i = 0; i < fileList.length; i++) {
				deleteDir(fileList[i].getAbsolutePath());
			}
			dirFile.delete();
		}
	}

}
